package com.baimawangzi.recovery.servlet.user;

import com.baimawangzi.recovery.service.impl.UserServiveImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
@WebServlet("/userdelete.do")//这里的/不能少否则部署错误相当恶心
public class UserDeleteServlet extends HttpServlet {
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        UserServiveImpl userServive = new UserServiveImpl();
        //解析url参数
        int id = Integer.parseInt(req.getParameter("id"));
        int a = userServive.delete(id);
        if(a>0){//提示信息
            req.setAttribute("msg","成功删除用户");
        }
        else {
            req.setAttribute("msg","删除用户失败，请先将该用户的物品记录和交易记录删除");
        }
        try {
            req.getRequestDispatcher("userlist.do").forward(req,resp);
        } catch (IOException e) {
            throw new RuntimeException(e);
        }
    }
}
